/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.auto.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.alibaba.common.lang.Paginator;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.MessageParamDAO;
import com.alipay.supergw.common.dal.share_supergw.auto.dataobject.MessageParamDO;
import com.iwallet.biz.common.util.PageList;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.MessageParamDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_message_param.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisMessageParamDAO extends SqlMapClientDaoSupport implements MessageParamDAO {

    /**
     *  Query DB table <tt>sgw_message_param</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, channel_system_id, param_type, param_name, param_value, memo, gmt_create, gmt_modified from sgw_message_param</tt>
     *
     *	@return List<MessageParamDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<MessageParamDO> loadAll() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-MESSAGE-PARAM-LOAD-ALL", null);

    }

    /**
     *  Query DB table <tt>sgw_message_param</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, channel_system_id, param_type, param_name, param_value, memo, gmt_create, gmt_modified from sgw_message_param where (id = ?)</tt>
     *
     *	@param id
     *	@return MessageParamDO
     *	@throws DataAccessException
     */
    public MessageParamDO selectById(int id) throws DataAccessException {
        Integer param = new Integer(id);

        return (MessageParamDO) getSqlMapClientTemplate().queryForObject(
            "MS-MESSAGE-PARAM-SELECT-BY-ID", param);

    }

    /**
     *  Insert one <tt>MessageParamDO</tt> object to DB table <tt>sgw_message_param</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into sgw_message_param(id,channel_system_id,param_type,param_name,param_value,memo,gmt_create,gmt_modified) values (?, ?, ?, ?, ?, ?, sysdate, sysdate)</tt>
     *
     *	@param messageParam
     *	@return int
     *	@throws DataAccessException
     */
    public int insert(MessageParamDO messageParam) throws DataAccessException {
        if (messageParam == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-MESSAGE-PARAM-INSERT", messageParam);

        return messageParam.getId();
    }

    /**
     *  Delete records from DB table <tt>sgw_message_param</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>delete from sgw_message_param where (id = ?)</tt>
     *
     *	@param id
     *	@return int
     *	@throws DataAccessException
     */
    public int delete(int id) throws DataAccessException {
        Integer param = new Integer(id);

        return getSqlMapClientTemplate().delete("MS-MESSAGE-PARAM-DELETE", param);
    }

    /**
     *  Query DB table <tt>sgw_message_param</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, channel_system_id, param_type, param_name, param_value, memo, gmt_create, gmt_modified from sgw_message_param</tt>
     *
     *	@param channelSystemId
     *	@param paramName
     *	@param paramType
     *	@param pageSize
     *	@param pageNum
     *	@return PageList
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public PageList select(String channelSystemId, String paramName, String paramType,
                           int pageSize, int pageNum) throws DataAccessException {
        Map param = new HashMap();

        param.put("channelSystemId", channelSystemId);
        param.put("paramName", paramName);
        param.put("paramType", paramType);
        param.put("pageSize", new Integer(pageSize));
        param.put("pageNum", new Integer(pageNum));

        Paginator paginator = new Paginator();
        paginator.setItemsPerPage(pageSize);
        paginator.setPage(pageNum);

        paginator.setItems(((Integer) getSqlMapClientTemplate().queryForObject(
            "MS-MESSAGE-PARAM-SELECT-COUNT-FOR-PAGING", param)).intValue());

        PageList pageList = new PageList();
        pageList.setPaginator(paginator);

        if (paginator.getBeginIndex() <= paginator.getItems()) {
            param.put("startRow", new Integer(paginator.getBeginIndex() == 0 ? 0 : paginator
                .getBeginIndex() - 1));
            param.put("endRow", new Integer(10));
            pageList.addAll(getSqlMapClientTemplate()
                .queryForList("MS-MESSAGE-PARAM-SELECT", param));
        }

        return pageList;
    }

    /**
     *  Query DB table <tt>sgw_message_param</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select id, channel_system_id, param_type, param_name, param_value, memo, gmt_create, gmt_modified from sgw_message_param</tt>
     *
     *	@param channelSystemId
     *	@param paramName
     *	@param paramType
     *	@return List<MessageParamDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public List<MessageParamDO> selectNoPage(String channelSystemId, String paramName,
                                             String paramType) throws DataAccessException {
        Map param = new HashMap();

        param.put("channelSystemId", channelSystemId);
        param.put("paramName", paramName);
        param.put("paramType", paramType);

        return getSqlMapClientTemplate().queryForList("MS-MESSAGE-PARAM-SELECT-NO-PAGE", param);

    }

    /**
     *  Update DB table <tt>sgw_message_param</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_message_param set param_type=?, param_name=?, param_value=?, memo=?, gmt_modified=sysdate where (id = ?)</tt>
     *
     *	@param messageParam
     *	@return int
     *	@throws DataAccessException
     */
    public int update(MessageParamDO messageParam) throws DataAccessException {
        if (messageParam == null) {
            throw new IllegalArgumentException("Can't update by a null data object.");
        }

        return getSqlMapClientTemplate().update("MS-MESSAGE-PARAM-UPDATE", messageParam);
    }

}